package com.android.projectsquirrel;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import android.content.Context;
import android.location.*;

public class GPSHelper  {
	
	public static Geocoder geocoder;
	public static double longitude;
	public static double latitude;
	
	public GPSHelper(Context con) {
		latitude = 0;
		longitude = 0;
		geocoder = new Geocoder (con);
	}
	
	public void updateCoordinates(double lat, double lon) {
		longitude = lon;
		latitude = lat;
	}
	
	//Call with get context...
	public String getZip(Context con, int latitude, int longitude) {
		List<Address> addresses = null;
		String postalCode;
		try {
			addresses = geocoder.getFromLocation(latitude, longitude, 2);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		if (addresses != null ) {
			if (addresses.size() > 0) {
				Iterator<Address> it = addresses.iterator();
				Address address = it.next();
				postalCode = address.getPostalCode();
				return postalCode;
			}
		}		
		return ""; //return the empty string if could not parse anything
	}

}
